/*
MCP2140
*/

#define BAUDRATE1		9600
#define BAUDRATEREG1 ((FREQ/BAUDRATE1)/32)-1

#define PIN_IN 1
#define PIN_OUT 0

#define RESET_IRDA PORTDbits.RD2  // PIC-->MCP 0 = esetto o esco da sleep
#define RTS_IRDA   PORTDbits.RD3  // PIC-->MCP 0 = PIC pronto per ricevere dato, se non settato MCP va in timeout
#define CD_IRDA    PORTBbits.RB4  // PIC-->MCP 0 = Carrier present  1= Non Carrier Present
#define DTR_IRDA   PORTDbits.RD4  // PIC-->MCP 0 = PC Ready per ricevere dato da MCP

#define PHACT_IRDA PORTBbits.RB3  // MCP-->PIC 0 = Basso in sleep
#define DSR_IRDA   PORTFbits.RF6  // MCP-->PIC 0 = Link OK stabilito segnalato dal MCP INT0
#define CTS_IRDA   PORTDbits.RD1  // MCP-->PIC 0 = Buffer vuoto 1=22byte, limite 64RX 29TX
 

// define Direzioni porte

#define DIR_RESET_IRDA TRISDbits.TRISD2  
#define DIR_PHACT_IRDA TRISBbits.TRISB3  
#define DIR_DSR_IRDA   TRISFbits.TRISF6  
#define DIR_RTS_IRDA   TRISDbits.TRISD3  
#define DIR_CD_IRDA    TRISBbits.TRISB4  
#define DIR_CTS_IRDA   TRISDbits.TRISD1  
#define DIR_DTR_IRDA   TRISDbits.TRISD4  

void __attribute__((interrupt, no_auto_psv)) _INT0Interrupt(void);
void __attribute__ ((interrupt, no_auto_psv)) _U1RXInterrupt(void);
void __attribute__ ((interrupt, no_auto_psv)) _U1TXInterrupt(void); 

void Init_IRDA(void); 
void Reset_IRDA(void);
void Abilita_IRDA(void);
void Disabilita_IRDA(void);
char PutChar_IRDA(char Dato_TX);
char Buff_Empty_IRDA(void);
void INT_RX_IRDA(char Byte_RX );
char Sleep_IRDA(void);
